#ifndef fscolour_h__
#define fscolour_h__
#include "math/coremath.h"

namespace gecko
{

// Class for describing colours.
class Colour
{
public:
	Colour(void);
	Colour(float _r, float _g, float _b, float _a);
	Colour(unsigned int colour);
	Colour(const Colour &colour);
	unsigned int ToInt() const;

	Colour& operator = (const Colour& colour);

	float GetR() const;
	float GetG() const;
	float GetB() const;
	float GetA() const;

	void SetR(float _r);
	void SetG(float _g);
	void SetB(float _b);
	void SetA(float _a);

	static Colour Black()   { return Colour(0.0f, 0.0f, 0.0f, 1.0f); };
	static Colour White()   { return Colour(1.0f, 1.0f, 1.0f, 1.0f); };
	static Colour Red()     { return Colour(1.0f, 0.0f, 0.0f, 1.0f); };
	static Colour Green()   { return Colour(0.0f, 1.0f, 0.0f, 1.0f); };
	static Colour Blue()    { return Colour(0.0f, 0.0f, 1.0f, 1.0f); };
	static Colour Magenta() { return Colour(1.0f, 0.0f, 1.0f, 1.0f); };
	static Colour Cyan()    { return Colour(0.0f, 1.0f, 1.0f, 1.0f); };
	static Colour Yellow()  { return Colour(1.0f, 1.0f, 0.0f, 1.0f); };
	static Colour Random();

private:
	float r;
	float g;
	float b;
	float a;
};


inline Colour::Colour(void)
: r(1.0f)
, g(1.0f)
, b(1.0f)
, a(1.0f)
{

}

inline Colour::Colour(float _r, float _g, float _b, float _a)
: r(_r)
, g(_g)
, b(_b)
, a(_a)
{
	
}

inline Colour::Colour(const Colour &colour)
: r(colour.r)
, g(colour.g)
, b(colour.b)
, a(colour.a)
{

}

inline Colour::Colour(unsigned int colour)
{
	b = (colour & 0xff)         / 255.0f;
	g = ((colour >> 8) & 0xff)  / 255.0f;
	r = ((colour >> 16) & 0xff) / 255.0f;
	a = ((colour >> 24) & 0xff) / 255.0f;
}

inline Colour& Colour::operator = (const Colour& colour)
{
	r = colour.r;
	g = colour.g;
	b = colour.b;
	a = colour.a;
	return *this;
}

inline unsigned int Colour::ToInt() const
{
	unsigned char _a = (unsigned char)(a * 255);
	unsigned char _r = (unsigned char)(r * 255);
	unsigned char _g = (unsigned char)(g * 255);
	unsigned char _b = (unsigned char)(b * 255);
	return (unsigned int)((((_a)&0xff)<<24)|(((_r)&0xff)<<16)|(((_g)&0xff)<<8)|((_b)&0xff));
}

inline float Colour::GetR() const
{
	return r;
}

inline float Colour::GetG() const
{
	return g;
}

inline float Colour::GetB() const
{
	return b;
}

inline float Colour::GetA() const
{
	return a;
}

inline void Colour::SetR(float _r)
{
	r = _r;
}

inline void Colour::SetG(float _g)
{
	g = _g;
}

inline void Colour::SetB(float _b)
{
	b = _b;
}

inline void Colour::SetA(float _a)
{
	a = _a;
}

inline Colour Colour::Random()
{
	return Colour(Rand<float>(), Rand<float>(), Rand<float>(), 1.0f);
}

}

#endif // fscolour_h__
